package com.aust.dynamicProxy.test3;

/**
 * 用户业务实现类（面向接口编程）
 */
public class UserServiceImpl implements UserService {
    @Override
    public void login(String username, String password) throws Exception {
//        long startTime = System.currentTimeMillis();

        if ("admin".equals(username) && "123456".equals(password)) {
            System.out.println("登录成功");
        } else {
            System.out.println("登录失败");
        }
        Thread.sleep(1000);

//        long endTime = System.currentTimeMillis();
//        System.out.println("login方法执行耗时：" + (endTime - startTime) + "ms");
    }

    @Override
    public void deleteUsers() throws Exception {
//        long startTime = System.currentTimeMillis();

        System.out.println("成功删除用户");
        Thread.sleep(1500);

//        long endTime = System.currentTimeMillis();
//        System.out.println("deleteUsers方法执行耗时：" + (endTime - startTime) + "ms");
    }

    @Override
    public String[] selectUsers() throws Exception {
//        long startTime = System.currentTimeMillis();

        System.out.println("查询出三个用户");
        String[] names = {"张三", "李四", "王五"};
        Thread.sleep(500);

//        long endTime = System.currentTimeMillis();
//        System.out.println("selectUsers方法执行耗时：" + (endTime - startTime) + "ms");
        return names;
    }

    public void test() throws InterruptedException {
        Thread.sleep(3000);
        System.out.println("test");
    }

    public void testInterface() throws Exception {
        System.out.println("testInterfaceBefore");
        Thread.sleep(3000);
        System.out.println("testInterfaceAfter");
    }
}
